public class Test {
    public static int mySqrt(int x) {
        int left = 0;
        int right = x;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if((long)mid * mid >= x) {
                right = mid;
            } else if((long)mid * mid < x) {
                left = mid + 1;
            }
        }
        if(left * left == x) {
            return left;
        }
        return left - 1;
    }
    class Solution {
        public int findMin(int[] nums) {
            int left = 0;
            int right = nums.length - 1;
            while(left < right) {
                if(nums[left] > nums[right]) {
                    left++;
                } else {
                    return nums[left];
                }
            }
            return nums[left];
        }
    }
    class Solution {
        public int peakIndexInMountainArray(int[] arr) {
            int left = 0;
            int right = arr.length - 1;
            while(left < right) {
                int mid = left + (right - left + 1) / 2;
                if(arr[mid] > arr[mid - 1]) {
                    left = mid;
                } else {
                    right = mid - 1;
                }
            }
            return left;
        }
    }
    public static void main(String[] args) {
        System.out.println(mySqrt(0));
    }
}
